﻿using System.Xml;
using System.Xml.Serialization;

namespace GISUtil.KML
{
  /// <summary>
  /// Contains methods for serializing and deserializing the XML found in the ItemIcon section of KML
  /// </summary>
  [XmlRoot("ItemIcon")]
  public class ItemIcon
  {
    /// <summary>
    /// The ItemIconMoe associated with this style. 
    /// </summary>
    [XmlElement("state")]
    public ItemIconMode? State { get; set; }

    private string _href;

    /// <summary>
    /// an HTTP address or path to load 
    /// </summary>
    [XmlElement("href")]
    public string href
    {
      get
      {
        return _href;
      }
      set
      {
        if (value.StartsWith("/"))
        {
          _href = ICNETServices.AWSConstants.KMLIconURL + value;
        }
        else
        {
          _href = value;
        }
      }
    }

    /// <summary>
    /// Determines if this class has any styling information associated with it. 
    /// </summary>
    /// <returns>True if at least one of the fields that contains style information has a value, otherwise false.</returns>
    public bool HasAValue()
    {
      return State != null || href != null;
    }
  }
}